package cn.itcast.bos.service.base.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.CourierDao;
import cn.itcast.bos.dao.base.FixeAreaDao;
import cn.itcast.bos.dao.base.TakeTimeDao;
import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.domain.base.FixedArea;
import cn.itcast.bos.domain.base.TakeTime;
import cn.itcast.bos.service.base.FixedAreaService;
@Service
@Transactional
public class FixedAreaServiceImpl implements FixedAreaService {
	//注入Dao层
	@Autowired
	private FixeAreaDao fd ;

	@Override
	public void save(FixedArea fa) {
		fd.save(fa);
	}

	@Override
	public Page<FixedArea> findPageData(Specification<FixedArea> sf, Pageable pb) {
		
		return fd.findAll(sf,pb);
	}
	@Autowired
	private CourierDao cd;
	@Autowired
	private TakeTimeDao ttd;
	@Override
	public void toFixedArea(FixedArea fa, Integer courierId, Integer takeTimeId) {
		//获取定区
		FixedArea fixedArea = fd.findOne(fa.getId());
		// 获得所有的快递员
		Courier courier = cd.findOne(courierId);
		//获取收派时间
		TakeTime takeTime = ttd.findOne(takeTimeId);
		//快递员关联定区
		fixedArea.getCouriers().add(courier);
		//收派标准关联快递员
		courier.setTakeTime(takeTime);
	}
	
}
